//package com.imay.live.fragment.room;
//
//import android.animation.Animator;
//import android.os.Bundle;
//import android.util.Log;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.TextView;
//
//import com.airbnb.lottie.LottieAnimationView;
//import com.imay.base.fragment.BaseDialogFragment;
//import com.imay.base.util.FileUtil;
//import com.imay.live.R;
//
//import org.json.JSONException;
//import org.json.JSONObject;
//
///**
// * Created by jeaman on 2017/5/10.
// */
//
//public class LevelUpgradeFragment extends BaseDialogFragment implements View.OnClickListener, Animator.AnimatorListener {
//    private final static String BUNDLE_NAME_LEVEL = "level";
//    private final static String BUNDLE_NAME_LIVE = "live";
//
//    private final static String IMAGE_ASSETS_FOLDER = "lottie_images/level_upgrade";
//    private final static String ONE_DIGITS_FILE = "lottie_level_upgrade_one.json";
//    private final static String TWO_DIGITS_FILE = "lottie_level_upgrade_two.json";
//
//    private LottieAnimationView mAnimationView;
//    private TextView mMessageTv;
//    private TextView mLevelOldTv;
//    private TextView mLevelNewTv;
//    private TextView mRewardTv;
//
//    private boolean mClose;
//
//    public static LevelUpgradeFragment newInstance(boolean live, int level) {
//        Bundle bundle = new Bundle();
//        bundle.putBoolean(BUNDLE_NAME_LIVE, live);
//        bundle.putInt(BUNDLE_NAME_LEVEL, level);
//        LevelUpgradeFragment fragment = new LevelUpgradeFragment();
//        fragment.setArguments(bundle);
//        return fragment;
//    }
//
//    @Override
//    protected int getLayoutId() {
//        return R.layout.fragment_level_upgrade;
//    }
//
//    @Override
//    protected void initView(Bundle savedInstanceState) {
//        mAnimationView = $(R.id.level_upgrade_lav_animation);
//        mMessageTv = $(R.id.level_upgrade_tv_message);
//        mLevelOldTv = $(R.id.level_upgrade_tv_old_level);
//        mLevelNewTv = $(R.id.level_upgrade_tv_new_level);
//        mRewardTv = $(R.id.level_upgrade_tv_reward);
//
//        $(R.id.level_upgrade_iv_close).setOnClickListener(this);
//        mAnimationView.setOnClickListener(this);
//        mAnimationView.useExperimentalHardwareAcceleration();
//
//        boolean live = getArguments().getBoolean(BUNDLE_NAME_LIVE);
//        int level = getArguments().getInt(BUNDLE_NAME_LEVEL);
//        mMessageTv.setText(live ? R.string.level_upgrade_anchor_upgrade : R.string.level_upgrade_self_upgrade);
//        mLevelOldTv.setText(getString(R.string.level_upgrade_level, level - 1));
//        mLevelNewTv.setText(getString(R.string.level_upgrade_level, level));
//
//        JSONObject animationJson = getAnimationJSON(live, level);
//        if (animationJson != null) {
//            mAnimationView.addAnimatorListener(this);
//            mAnimationView.setImageAssetsFolder(IMAGE_ASSETS_FOLDER);
//            mAnimationView.setAnimation(animationJson);
//            mAnimationView.playAnimation();
//        }
//    }
//
//    @Override
//    protected boolean isMatchParent() {
//        return true;
//    }
//
//    private JSONObject getAnimationJSON(boolean live, int level) {
//        JSONObject json = null;
//        int decade = level / 10;    //十位
//        int unit = level % 10;  //个位
//        String jsonString = FileUtil.readAssetsByName(getActivity(), decade == 0 ? ONE_DIGITS_FILE : TWO_DIGITS_FILE);
//        if (jsonString != null) {
//            jsonString = jsonString.replace("type_1.png", live ? "type_1.png" : "type_2.png");
//            jsonString = jsonString.replace("digits_unit.png", "digits_" + unit + ".png");
//            if (decade > 0) {
//                jsonString = jsonString.replace("digits_decade.png", "digits_" + decade + ".png");
//            }
//            try {
//                json = new JSONObject(jsonString);
//            } catch (JSONException e) {
//                e.printStackTrace();
//            }
//        }
//        return json;
//    }
//
//    @Override
//    public void onClick(View v) {
//        switch (v.getId()) {
//            case R.id.level_upgrade_iv_close:
//                dismiss();
//                break;
//            case R.id.level_upgrade_lav_animation:  //加速关闭
//                if (!mClose) {
//                    mClose = true;
//                    mAnimationView.removeAnimatorListener(this);
//                    mAnimationView.pauseAnimation();
//                    mAnimationView.setProgress(0.9f);
//                    mAnimationView.addAnimatorListener(this);
//                    mAnimationView.resumeAnimation();
//                }
//                break;
//        }
//    }
//
//    @Override
//    public void onAnimationStart(Animator animation) {
//
//    }
//
//    @Override
//    public void onAnimationEnd(Animator animation) {
//        if (isAdded()) {
//            dismiss();
//        }
//    }
//
//    @Override
//    public void onAnimationCancel(Animator animation) {
//
//    }
//
//    @Override
//    public void onAnimationRepeat(Animator animation) {
//
//    }
//}
